package logic

import (
	"context"
	"doctor-medicine-system/models/mysql"

	"doctor-medicine-system/systemrpc/internal/svc"
	"doctor-medicine-system/systemrpc/systemrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsAddLogic {
	return &GoodsAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 添加
func (l *GoodsAddLogic) GoodsAdd(in *systemrpc.GoodsAddRequest) (*systemrpc.GoodsAddResponse, error) {
	// todo: add your logic here and delete this line
	goods := mysql.Goods{
		Name:    in.Name,
		Context: in.Context,
		Comment: in.Comment,
		Price:   in.Price,
	}
	err := goods.GoodsAdd(mysql.DB)
	if err != nil {
		return nil, err
	}
	return &systemrpc.GoodsAddResponse{
		GoodsId: int64(goods.ID),
	}, nil
}
